package com.edu.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import com.edu.dao.BaseDao;
import com.edu.dao.indexDo;
import com.edu.entity.Conditions;
import com.edu.entity.Goods;
import com.edu.entity.Prom;

public class indexDaoImpl implements indexDo {
	BaseDao bd1 = new BaseDao();
	GoodDaoImpl gdi = new GoodDaoImpl();
	@Override
	public ArrayList<Prom> sqlFindProm() {
		// TODO Auto-generated method stub
		ArrayList<Prom> list = new ArrayList();
		String sql = "select * from promotion";
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		conn = bd1.getConn();
		try {
			ps = conn.prepareStatement(sql);
			rs = ps.executeQuery();
			while(rs.next()) {
				Goods g = new Goods();
				Conditions con = new Conditions();
				Prom p = new Prom();
				p.setPromid(rs.getInt(1));
				p.setTitle(rs.getString(2));
				p.setInfo(rs.getString(3));
				p.setButtonText(rs.getString(4));
				p.setBackimg(rs.getString(5));
				g.setGoodid(rs.getInt(6));
				p.setGoods(gdi.sqlFindGoods(g, con).get(0));
				list.add(p);
			}
			return list;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			bd1.closeAll(conn, ps, rs);
		}
		return null;
	}

}
